package com.gmadmin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gmadmin.entity.SysDict;
import com.gmadmin.mapper.SysDictMapper;
import com.gmadmin.service.SysDictService;
import com.gmadmin.entity.vo.dict.SysDictDetailVo;
import com.gmadmin.entity.vo.dict.SysDictVo;
import com.gmadmin.utils.CollectionBeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhangliang
 * @version 1.0
 * @date 2022/6/9 13:35
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    private final SysDictMapper dictMapper;

    public SysDictServiceImpl(SysDictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    @Override
    public List<SysDictVo> getDictByNames(List<String> dictNames) {
        System.out.println(dictNames);
        List<SysDict> sysDicts = dictMapper.getDictByNames(dictNames);
        List<SysDictVo> sysDictVos = sysDicts.stream().map(sysDict -> {
            SysDictVo sysDictVo = new SysDictVo();
            CollectionBeanUtils.copyProperties(sysDict, sysDictVo);
            sysDictVo.setDictDetails(CollectionBeanUtils.copyListProperties(sysDict.getDictDetails(), SysDictDetailVo::new));
            return sysDictVo;
        }).collect(Collectors.toList());


        return sysDictVos;
    }
}
